package com.jiudengnile.liushu.biz.dal.ibatis;

import java.util.List;

import com.jiudengnile.liushu.biz.dal.dao.PermissionDAO;
import com.jiudengnile.liushu.biz.dal.ibatis.base.BaseIbatisDaoSupport;
import com.jiudengnile.liushu.biz.domains.permission.PermissionDO;
import com.jiudengnile.liushu.biz.query.ListWithTotalCount;
import com.jiudengnile.liushu.biz.query.PermissionQuery;

public class PermissionDAOIbatis extends BaseIbatisDaoSupport implements PermissionDAO {
	
	public long create(PermissionDO permission) {
		return (Long)this.getSqlMapClientTemplate().insert("PermissionDAO.create", permission);
	}

	public void delete(long id) {
		this.getSqlMapClientTemplate().update("PermissionDAO.delete", id);
	}

	public void update(PermissionDO permission) {
		this.getSqlMapClientTemplate().update("PermissionDAO.update", permission);
	}

	public PermissionDO queryById(long id) {
		return (PermissionDO)this.getSqlMapClientTemplate().queryForObject("PermissionDAO.queryById", id);
	}

	@Override
	public PermissionDO queryByCode(String code) {
		return (PermissionDO)this.getSqlMapClientTemplate().queryForObject("PermissionDAO.queryByCode", code);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PermissionDO> queryByIds(List<Long> ids) {
		return (List<PermissionDO>)this.getSqlMapClientTemplate().queryForList("PermissionDAO.queryByIds", ids);
	}
	
	@SuppressWarnings("unchecked")
	public ListWithTotalCount<PermissionDO> queryForPage(PermissionQuery permissionQuery) {
		List<PermissionDO> permissions = (List<PermissionDO>)this.getSqlMapClientTemplate().queryForList("PermissionDAO.queryForPage", permissionQuery);
		Integer totalCount = (Integer)this.getSqlMapClientTemplate().queryForObject("PermissionDAO.queryForCount", permissionQuery);
		ListWithTotalCount<PermissionDO> ret = new ListWithTotalCount<PermissionDO>(permissions);
		ret.setTotalCount(totalCount);
		return ret;
	}

}
